﻿Public Class FrmChinh

    Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CreateConfigTable()
        db=new DbConnect
        Try
            config.ReadXml(configFile & ".xml")

        Catch ex As Exception
        End Try
        If config.Rows.Count = 1 Then
            If config.Rows(0)("XacThuc") = 0 Then
                db.Connect(config.Rows(0)("TenMayChu"), config.Rows(0)("TenCSDL"))
            Else
                db.Connect(config.Rows(0)("TenMayChu"), config.Rows(0)("TenCSDL"), config.Rows(0)("TenNguoiDung"), base64Decode(config.Rows(0)("MatKhau")))
            End If
        End If

        If Not db.IsConnected Or config.Rows.Count <> 1 Then 'neu ko tim thay file config hoac file config bi sai
            Dim f As New FrmCauHinhCSDL
            f.ShowDialog()
        End If
        'MsgBox(My.Settings.MaNV)
        If My.Settings.NhoMK Then
            NhanVien.DangNhap(My.Settings.MaNV, My.Settings.MatKhau)
        End If

    End Sub

    Private Sub FrmMain_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        If Not db.IsConnected Then
            MsgBox("Không thể kết nối tới CSDL!", MsgBoxStyle.Critical, "Lỗi")
            Close()
        End If
        If Not NhanVien.DaDangNhap Then
            Dim f As New FrmDangNhap
            f.ShowDialog()
        End If
    End Sub

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub NhàCungCấpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NhàCungCấpToolStripMenuItem.Click
        Dim f As New FrmNhaCungCap
        OpenChildForm(Me, f)
    End Sub

    Private Sub ĐơngiáThuêToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐơngiáThuêToolStripMenuItem.Click
        Dim f As New FrmGiaThue
        OpenChildForm(Me, f)
    End Sub

    Private Sub KháchHàngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KháchHàngToolStripMenuItem.Click
        Dim f As New FrmKhachHang
        OpenChildForm(Me, f)
    End Sub

    Private Sub ThoátToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThoátToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub ĐăngNhậpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐăngNhậpToolStripMenuItem.Click

    End Sub


    Private Sub KhachHangToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim f As New FrmKhachHang
        OpenChildForm(Me, f)
    End Sub

    Private Sub HangToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HangToolStripMenuItem.Click
        Dim f As New FrmHangSanXuat
        OpenChildForm(Me, f)

    End Sub
    Private Sub HinhThưcThuêToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HinhThưcThuêToolStripMenuItem.Click
        Dim f As New FrmHinhThucThue
        OpenChildForm(Me, f)
    End Sub

    Private Sub HinhThưcThanhToanToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HinhThưcThanhToanToolStripMenuItem.Click
        Dim f As New frmHinhThucThanhToan
        OpenChildForm(Me, f)
    End Sub

    Private Sub ThôngKêBaoCaoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThôngKêBaoCaoToolStripMenuItem.Click

    End Sub

    Private Sub TinhTrangXeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TinhTrangXeToolStripMenuItem.Click
        Dim f As New FrmTinhTrangXe
        OpenChildForm(Me, f)
    End Sub

    Private Sub MượnXeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MượnXeToolStripMenuItem.Click
        Dim f As New FrmPhieuMuon
        OpenChildForm(Me, f)
    End Sub

    Private Sub CấuHìnhKếtNốiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CấuHìnhKếtNốiToolStripMenuItem.Click
        Dim f As New FrmCauHinhCSDL
        f.ShowDialog
    End Sub
    Private Sub XeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XeToolStripMenuItem.Click
        Dim f As New FrmXe
        OpenChildForm(Me, f)
    End Sub

    Private Sub LoaiXeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoaiXeToolStripMenuItem.Click
        Dim f As New FrmLoaiXe
        OpenChildForm(Me, f)
    End Sub
End Class
